﻿@{
    ViewBag.Title = "ClearPoint";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>     
}

       
<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="refresh" plain="true">刷新</a>
                 <span class="separator"></span>
                <a class="mini-button" id="clearpoint" name="clearpoint" iconCls="icon-remove" onclick="clearPoint" plain="true">清除积分</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>       
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
            borderStyle="border:1;" url="../Member/GetMemberTypeList"
            allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
            onrowdblclick="modify"  sortMode="client" multiSelect="true">
        <div property="columns">
            <div type="checkcolumn" >选行</div>
            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
            <div field="FNumber" name="FNumber" width="150" headeralign="center" allowsort="true">分类编码</div>
            <div field="FName" name="FName" width="200" headeralign="center" allowsort="true">分类名称</div>
        </div>
    </div>
</div>

<script>
    mini.parse();
    var grid = mini.get("datagrid1");

    function FormShown() {        
        LoadListData();
    }

    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
            var json = "[{";
            json = json + '"FSystemAppID":' + '"' + sSystemAppID + '"';
            json = json + "}]";
            grid.load({ json: json });
    }

    //刷新
    function refresh() {
        mini.getbyName("FNumber").setValue('');
        LoadListData();
    }

    function show_load() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
    }

    function hide_load() {
        mini.unmask(document.body);
    }

    function clearPoint() {
        mini.confirm("所选分类下的会员积分将被清除，是否继续清除？", "提示",
            function (action) {
                if (action == "ok") {
                    mini.getbyName("clearpoint").setEnabled(false);
                    mini.open({
                        url: "../Member/ValidPwd",
                        title: "用户验证", width: 487, height: 190,
                        onload: function () {
                        },
                        ondestroy: function (action) {
                            if (action == -1) {
                                mini.alert("密码验证错误");
                            } 
                            else if(action == 1)
                                clear();
                            mini.getbyName("clearpoint").setEnabled(true);
                        }
                    });
                }
                else
                    return;
            });
    }

    function clear() {
        var rows = grid.getSelecteds();
        if (rows.length>0) {
            var mIDs = '';
            for (var i = 0; i < rows.length; i++) {
                if (i > 0) mIDs += ',';
                mIDs += rows[i].FItemID;
            }
            var json = '[{"mSystemAppID":"'+parent.window.getSystemAppID()+'","mIDs":"'+mIDs+'"}]';
            show_load();
            $.post("PointClear", { mjson: json }, function (data) {
                var ret = mini.decode(data);
                debugger;
                if (ret.status == 1) {
                    mini.alert("积分清除完成.");
                }
                else {
                    mini.alert("积分清除失败! "+ret.error);
                }
                hide_load();
                mini.getbyName("clearpoint").setEnabled(true);
            })
            .error(function(){
                hide_load();
                mini.getbyName("clearpoint").setEnabled(true);
            });
        }
        else {
            mini.alert("请选择至少一个会员分类再清除积分.");
            mini.getbyName("clearpoint").setEnabled(true);
        }
    }

</script>
